<?php
declare(strict_types = 1);

namespace app\controller;

use app\BaseController;
use think\Request;

class Upload extends BaseController
{
    public function add(Request $request)
    {
        $file = request()->file('image');
        // 上传到本地服务器
        $saveName = \think\facade\Filesystem::disk('public')->putFile('topic', $file);
        return $this->createJsonResponse([
            'avatar' => str_replace('\\', '', '/storage/' . $saveName)
        ]);
    }
}
